package com.pinfly.common.config;

import java.util.HashMap;

/**
 * This class extends a HashMap to provide a mechanism for retrieving a specific
 * CfgProperties object based on the group name. The group name is
 * case-insensitive. The GroupMap object is returned on methods of objects that
 * implement the ICfgProperties interface.
 * 
 */
public class GroupMap extends HashMap <String, PfyProperties>
{
    private static final long serialVersionUID = 6709890271899549949L;

    public GroupMap ()
    {
        super ();
    }

    /**
     * Puts the CxxProperties in the Map using the specified group. The group
     * name is shifted to lowercase. If the group already existed in the map the
     * value will be replaced.
     * 
     * @param group
     * @param prop
     */
    public void setProperties (String group, PfyProperties prop)
    {
        String key = group.toLowerCase ();
        put (key, prop);
    }

    /**
     * Returns the CxxProperties object that corresponds to the specified group.
     * If it does not exists a NULL is returned.
     * 
     * @param group
     * @return CxxProperties or a NULL if the group does not exist.
     */
    public PfyProperties getProperties (String group)
    {
        String key = group.toLowerCase ();
        if (this.containsKey (key))
        {
            return (PfyProperties) get (key);
        }
        else
        {
            return null;
        }
    }
}
